package com.eupmt.lab3.controllers.impl;

import com.eupmt.lab3.controllers.IClientController;
import com.eupmt.lab3.domain.Client;
import com.eupmt.lab3.domain.Producte;
import com.eupmt.lab3.persistence.ibatis.dao.ClientDaoManager;
import com.eupmt.lab3.utils.Log;

/**
 *
 * @author Aarón
 */
public class ClientController implements IClientController {

    //Atributes
    protected static ClientController instance = null;
    ClientDaoManager dao = null;
    private Log log = null;

    //Constructors
    private ClientController() {
        log = new Log();
    }

    // Metodes Controller
    public void saveClient(Client client) throws Exception {
        dao = ClientDaoManager.getInstance();
        dao.saveClient(client);
    }

    public void insertClient(Client client) throws Exception {
        dao = ClientDaoManager.getInstance();
        dao.insertClient(client);
    }

    public void updateClient(Client client) throws Exception {
        dao = ClientDaoManager.getInstance();
        dao.updateClient(client);
    }

    public void deleteClient(Client client) throws Exception {
        dao = ClientDaoManager.getInstance();
        dao.deleteClient(client);
    }

    public Client getClientById(int idClient) throws Exception {
        dao = ClientDaoManager.getInstance();
        return dao.getClientById(idClient);
    }

    public Client getClientByNif(String nif) throws Exception {
        dao = ClientDaoManager.getInstance();
        return dao.getClientByNif(nif);
    }

    public Client getClientByProducte(Producte producte) throws Exception {
        //TODO getClientByProducte
        throw new UnsupportedOperationException("Not supported yet.");
    }

    // Patro Singleton
    public static ClientController getInstance() {
        if (instance == null) {
            instance = new ClientController();
        }
        return instance;
    }
}
